var app=getApp();
var c=require('../common.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    deletecore:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var user_id = wx.getStorageSync("userInfo").user_id;
     c.ajax(
       app.url+'myinfo',
       { user_id: user_id},
       res=>{
         var data = res.data;
         var integral = data.integral;
         var bi = parseInt(integral / 100);
         this.setData({ data: res.data, bi: bi})
       }
     )
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  num:function(e){
    var num=e.detail.value;
    var deletecore=num*100;
    this.setData({ deletecore: deletecore, num: num})
  },
  sureclick:function(){
    var user_id = wx.getStorageSync("userInfo").user_id;
    var num=this.data.num;
    var that=this;
    c.ajax(
      app.url +'duihuan',
      { uid: user_id, code:num*100},
      res=>{
        console.log(res);
       if(res.data==101){
         wx.showToast({
           title: '积分不足',
           icon: 'flase',
           image: '../img/error.png',
           duration:2000,
           mask: true,
           success: function(res) {},
           fail: function(res) {},
           complete: function(res) {},
         })
       }else{
         wx.showToast({
           title: '兑换成功',
         })
         setTimeout(function(){
           that.onLoad();
           that.setData({ deletecore: 0, value:0})
         },2000)
       };
      }
    )
  }
})